function nb = getNearestNeighbourRatio(frames, descriptors)
nkeypoints = size(frames, 2);
nbr = zeros(1, nkeypoints);
nb = zeros(1, nkeypoints);
distmat = zeros(nkeypoints, nkeypoints);
for i = 1:nkeypoints
    mindist = Inf;
    mindist2 = Inf;
    minj = NaN;
    %for j = i+1:nkeypoints
    for j = 1:nkeypoints
        if i == j
            continue;
        end
        dist = norm(descriptors(:, i) - descriptors(:, j), 2);
        distmat(i,j) = dist;
        if dist < mindist
            mindist2 = mindist;
            mindist = dist;
            minj = j;
        elseif dist < mindist2
            mindist2 = dist;
        end
    end
    nbr(i) = mindist / (mindist2 + eps);
    if nbr(i) < 0.6
        nb(i) = minj;
    else
        nb(i) = NaN;
    end
end
end
